import os
import pygame


# 获取当前项目的路径
projectPath=os.path.abspath('..')

# 我的飞机类
class MyPlane(pygame.sprite.Sprite):
    def __init__(self,bg_Size):
        self.image1=pygame.image.load(projectPath+"/resources/images/me1.png").convert_alpha()
        self.image2=pygame.image.load(projectPath+"/resources/images/me2.png").convert_alpha()
        self.destroyImages=[]
        self.destroyImages.append(pygame.image.load(projectPath+"/resources/images/me_destroy_1.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath+"/resources/images/me_destroy_2.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath+"/resources/images/me_destroy_3.png").convert_alpha())
        self.destroyImages.append(pygame.image.load(projectPath+"/resources/images/me_destroy_4.png").convert_alpha())
        self.rect=self.image1.get_rect()
        self.width=bg_Size[0]
        self.height=bg_Size[1]
        self.rect.left=(self.width-self.rect.width)//2
        self.rect.top=self.height-self.rect.height
        self.speed=10
        self.active = True
        self.mask=pygame.mask.from_surface(self.image1)

    # 向上移动
    def moveUp(self):
        if self.rect.top>0:
            self.rect.top-=self.speed
        else:
            self.rect.top=0

    # 向下移动
    def moveDown(self):
        if self.rect.bottom < self.height:
            self.rect.bottom += self.speed
        else:
            self.rect.bottom = self.height

    # 向左移动
    def moveLeft(self):
        if self.rect.left > 0:
            self.rect.left -= self.speed
        else:
            self.rect.left = 0

    # 向右移动
    def moveRight(self):
        if self.rect.right<self.width:
            self.rect.right += self.speed
        else:
            self.rect.right = self.width

    # 复活我方飞机
    def revive(self):
        self.rect.left = (self.width - self.rect.width) // 2
        self.rect.top = self.height - self.rect.height
        self.active = True

